package com.msb.mall.product.web;

import com.msb.mall.product.entity.CategoryEntity;
import com.msb.mall.product.service.CategoryService;
import com.msb.mall.product.vo.Catelog2VO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @Auther: xixifeng
 * @Date: 2022/10/20 - 10 - 20 - 15:11
 * @Description: com.msb.mall.product.web
 * @version: 1.0
 */

@Controller
public class indexController {

    @Autowired
    CategoryService categoryService;

    /**
     *查询出所有的商品大类(一级分类)
     */
    @RequestMapping({"/","index","home"})
    public String index(Model model) {
        // 查询出所有的一级分类的信息
        List<CategoryEntity> list=categoryService.getLevelCategory();
        model.addAttribute("category", list);
        // classPath:/templates/
        // .html
        return "index";
    }


    /**
     * 查询出所有的一级分类所对应的二级和三级分类
     *
     */
    //index/catalog.json
    @RequestMapping("/index/catalog.json")
    @ResponseBody
    public Map<String,List<Catelog2VO>> getCateLog2JSON() {

        Map<String, List<Catelog2VO>> map = categoryService.getCateLog2JSON();

        return map;
    }

}
